def simple(a):
    a = int(a)
    b = True
    i = 2
    while b:
        if a % i == 0:
            b = False
            break
        i += 1
        if i > a / 2:
            break
    if a == 1:
        b = False
    if a == 2:
        b = True
    return b
def mm(s):
    m = Max
    if s > m:
        m = s
    return m


Max = 1
p = input()
ui = False
if len(p) == 4:
    for i in range(4):
        if p[i] not in '0123456789':
            print(0)
            break
        else:
            ui = True
            for i in range(4):
                b = simple(p[i])
                if b == True:
                    Max = mm(int(p[i]))

            for i in range(3):
                b = simple(p[i] + p[i+1])
                if b == True:
                    Max = mm(int(p[i] + p[i+1]))

            for i in range(2):
                b = simple(p[i] + p[i+1] + p[i + 2])
                if b == True:
                    Max = mm(int(p[i] + p[i+1] + p[i + 2]))
            b = simple(p)
            if b == True:
                Max = mm(int(p))



else:
    if ui == False:
        print(0)
if Max > 1:
    print(Max)
else:
    print(0)

                    
            
    
